/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.address;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class HttpURIImpl extends URIBase {
    private String host;
    private Integer port;
    private String path;
    private boolean isSecure;

    private final static HttpURIParser parser = new HttpURIParser();

    protected URIParser getParser() {
        return parser;
    }

    public HttpURIImpl() {
        super("http");
    }

    public Object clone() {
        final HttpURIImpl uri = new HttpURIImpl();
        uri.cloneInternals(this);
        if (parsed) {
            uri.host = this.host;
            uri.path = this.path;
        }
        return uri;
    }

    /**
     * This method determines if this is a URI with a scheme of "sip" or "sips".
     *
     * @return true if the scheme is "sip" or "sips", false otherwise.
     */
    public final boolean isSipURI() {
        parse();
        return false;
    }

    public boolean isSecure() {
        parse();
        return isSecure;
    }

    public void setSecure(boolean secure) {
        parse();
        isSecure = secure;
        invalidateStringValue();
    }

    public String getHost() {
        parse();
        return host;
    }

    public void setHost(String host) {
        parse();
        this.host = host;
        invalidateStringValue();
    }

    public int getPort() {
        parse();
        return port == null ? 80 : port;
    }

    public void setPort(int port) {
        parse();
        this.port = port;
        invalidateStringValue();
    }

    public String getPath() {
        parse();
        return path;
    }

    public void setPath(String path) {
        parse();
        this.path = path;
        invalidateStringValue();
    }

    protected String buildStringValue() {
        final StringBuilder sb = new StringBuilder();
        sb.append(getScheme()).append("://");
        sb.append(host);
        if (path!=null) sb.append(path);
        return sb.toString();
    }

    protected static HttpURIImpl createLazily(String rawURI) {
        return createLazily(rawURI.getBytes(), 0, rawURI.length());
    }

    protected static HttpURIImpl createLazily(byte[] rawURI, int start, int end) {
        final HttpURIImpl uri = new HttpURIImpl();
        uri.data = rawURI;
        uri.start = start;
        uri.end = end;
        uri.parsed = false;
        return uri;
    }
}
/*
 * $Log$
 */